package com.example.padtestproject;

import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager2 viewPager;
    private ViewPagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String songName = getIntent().getStringExtra("songName");
//
//        TextView textView = findViewById(R.id.songNameTextView);
//        textView.setText(songName != null ? "Now Playing: " + songName : "No Song Selected");

        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);

        // Setup ViewPager Adapter
        adapter = new ViewPagerAdapter(this);
        adapter.addFragment(SampleFragment.newInstance(songName), "Tab 1");
        adapter.addFragment(new SampleFragment2(), "Tab 2");
        adapter.addFragment(new SampleFragment3(), "Tab 3");

        viewPager.setAdapter(adapter);

        // Link TabLayout and ViewPager2
        new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
            tab.setText(adapter.getTitle(position));
        }).attach();

        ImageButton backButton = findViewById(R.id.backButton);
        backButton.setOnClickListener(v -> {
            onBackPressed(); // 返回上一页面
        });
    }
}